#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long t,n,m,L,V,ans,mp;
long long d[100001],v[100001],a[100001],p[100001];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
            ans=0;
            mp=0;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++)
            cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++){
            cin>>p[i];
            mp=max(p[i],mp);
            }
        for(int i=1;i<=n;i++)
        if(v[i]>V&&mp>=d[i])
            ans++;
        cout<<ans<<' '<<m-1;
    }
    return 0;
}
